package org.bot.plugin.web.event;

import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.plugin.web.util.WebApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 沧月
 * @create 0012 2023/9/12 17:46
 * @description <设置全局变量值>
 * <p>
 * config   {"cmd":"org.bot.plugin.web.event.WebGlobalValue","arg":"变量KEY","dataIndex":"数据索引：0"}
 */
@Component
@EventName("添加全局属性")
public class WebGlobalValue implements Events {

    @Autowired
    WebApi webApi;

    @Override
    public Object exec(FlowNode note, DataStorage data) {
        webApi.setGlobalValue(webApi.getWebDriver(note), note.getArg(), data.get(note.getDataIndex()));
        return null;
    }
}
